<?php

namespace app\admin\model\users;

use think\Model;


class Users extends Model
{

    

    

    // 表名
    protected $name = 'users';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sex_text',
        'bot_text',
        'online_text',
        'sign_notice_text',
        'logintime_text'
    ];
    

    
    public function getSexList()
    {
        return ['0' => __('Sex 0'), '1' => __('Sex 1')];
    }

    public function getBotList()
    {
        return ['0' => __('Bot 0'), '1' => __('Bot 1')];
    }

    public function getOnlineList()
    {
        return ['0' => __('Online 0'), '1' => __('Online 1')];
    }

    public function getSignNoticeList()
    {
        return ['0' => __('Sign_notice 0'), '1' => __('Sign_notice 1')];
    }


    public function getSexTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBotTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['bot']) ? $data['bot'] : '');
        $list = $this->getBotList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOnlineTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['online']) ? $data['online'] : '');
        $list = $this->getOnlineList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSignNoticeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sign_notice']) ? $data['sign_notice'] : '');
        $list = $this->getSignNoticeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getLogintimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setLogintimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}
